﻿(function ($) {
    $.check = {
        //全选
        selectall: function (items) {
            items.each(function () {
                if (!$(this)[0].checked) {
                    $(this).click();
                }
            });
        },
        //反选
        reverseall: function (items) {
            items.each(function () {
                $(this).click();
            });
        },
        //移除所有选项
        removeall: function (items) {
            items.each(function () {
                if ($(this)[0].checked) {
                    $(this).click();
                }
            });
        }
    };
    $.alert = {
        defaulta: function (title, content, Callback) {
            var strVar = "";
            strVar += "<div id=\"alert\" class=\"modal hide fade in\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"myModalLabel\" aria-hidden=\"false\" style=\"display: block;\">";
            strVar += "	<div class=\"modal-header\">";
            strVar += "		<button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-hidden=\"false\">×<\/button>";
            strVar += "		<h3 id=\"myModalLabel\">" + title + "<\/h3>";
            strVar += "	<\/div>";
            strVar += "	<div class=\"modal-body\">";
            strVar += content;
            strVar += "	<\/div>";
            strVar += "	<div class=\"modal-footer\">";
            strVar += "		<button class=\"btn\" data-dismiss=\"modal\" aria-hidden=\"true\">关闭<\/button>";
            strVar += "	<\/div>";
            strVar += "<\/div>";
            strVar += "<div class=\"modal-backdrop fade in alertContainer\">";
            strVar += "<\/div>";

            $('body').append(strVar);
            $('body').delegate("#alert .modal-footer .btn:first-child", "click", function () {
                $('#alert').remove();
                $('.alertContainer').remove();
                if (Callback) {
                    Callback();
                }
            });
            $('body').delegate('#alert .close', 'click', function () {
                $('#alert').remove();
                $('.alertContainer').remove();
                if (Callback) {
                    Callback();
                }
            });
        },
        confirm: function (title, content, ok, Callback) {
            var strVar = "";
            strVar += "<div id=\"alert\" class=\"modal hide fade in\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"myModalLabel\" aria-hidden=\"false\" style=\"display: block;\">";
            strVar += "	<div class=\"modal-header\">";
            strVar += "		<button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-hidden=\"false\">×<\/button>";
            strVar += "		<h3 id=\"myModalLabel\">" + title + "<\/h3>";
            strVar += "	<\/div>";
            strVar += "	<div class=\"modal-body\">";
            strVar += content;
            strVar += "	<\/div>";
            strVar += "	<div class=\"modal-footer\">";
            strVar += "		<button class=\"btn\" data-dismiss=\"modal\" aria-hidden=\"true\">关闭<\/button>";
            strVar += "		<button class=\"btn btn-primary\">确定<\/button>";
            strVar += "	<\/div>";
            strVar += "<\/div>";
            strVar += "<div class=\"modal-backdrop fade in alertContainer\">";
            strVar += "<\/div>";


            $('body').append(strVar);

            $('body').delegate("#alert .modal-footer .btn:first-child", "click", function () {
                alertcolse();
                if (Callback) {
                    Callback();
                }
            });
            $('body').delegate('#alert .close', 'click', function () {
                alertcolse();
            });
            $('body').delegate('#alert .modal-footer .btn-primary', 'click', function () {
                if (ok) {
                    ok();
                } else {
                    console.warn('未定义确定按钮的事件');
                }
                alertcolse();
                if (Callback) {
                    Callback();
                }
            });
            function alertcolse() {
                $('#alert').remove();
                $('.alertContainer').remove();
            }
        }
    };
})(jQuery)